package ms.actuator.job.hander;

import ms.actuator.job.common.ApiContent;
import ms.actuator.job.feign.MindrayFeign;
import ms.actuator.job.service.AedApiInfoService;
import com.github.benmanes.caffeine.cache.Cache;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.time.format.DateTimeFormatter;

/**
 * 迈瑞 IOT 平台
 *
 * @Author ybc
 * @Date 2021/6/23 15:57
 */
@Component
@Slf4j
public class MindrayJob {

    private final DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:00");

    private final RedisTemplate<String, Object> redisTemplate;

    private final MindrayFeign mindrayFeign;

    private final Cache<String, Object> caffeineCache;

    private final AedApiInfoService aedApiInfoService;

    @Autowired
    public MindrayJob(RedisTemplate<String, Object> redisTemplate,
                      MindrayFeign mindrayFeign,
                      Cache<String, Object> caffeineCache,
                      AedApiInfoService aedApiInfoService) {
        this.redisTemplate = redisTemplate;
        this.mindrayFeign = mindrayFeign;
        this.caffeineCache = caffeineCache;
        this.aedApiInfoService = aedApiInfoService;
    }

    /**
     * 从数据库中获取数据更新到内存
     */
    @XxlJob("reloadApiInfo")
    public void reloadApiInfo(){
        aedApiInfoService.putInfo2Cache();
    }

    @XxlJob("mindrayTest")
    public void mindrayTest() {
//        LocalDateTime now = LocalDateTime.now();
//        LocalDateTime startTime = now.minusDays(2);
//        log.info("startTime : {} , endTime : {}", startTime.format(df), now.format(df));
//        String results = mindrayFeign.getPrehospitalTasks();
//        log.info(results);
        log.info(">>>>>>>>>>>>>>>>>> key : {}",caffeineCache.getIfPresent(ApiContent.API_REQ_INFO_KEY + ApiContent.API_NAME_MINDRAY));
        log.info(">>>>>>>>>>>>>>>>>> secret: {}",caffeineCache.getIfPresent(ApiContent.API_REQ_INFO_SECRET + ApiContent.API_NAME_MINDRAY));
    }


}
